14. Finding a random divisor: Finding a Random Divisor of a vli Object
Description
divisor returns a randomly chosen divisor of a given number.
Usage
divisor(n, iter = 100)
# S3 method for default
divisor(n, iter = 100)
# S3 method for numeric
divisor(n, iter = 100)
# S3 method for vli
divisor(n, iter = 100)
Value
object of class vli
Arguments
n
object of class vli or 32 bits integer
iter
number of iterations for testing if the given number is prime; numeric
Author
Javier Leiva Cuadrado
Details
The algorithm determines if the given number is prime or composite by usign the Miller-Rabin Probabilistic Primality Test. If it is prime, it returns the number itself. If it is composite, it returns a randomly chosen divisor. The number of iterations is configurable to set the desired accuracy. A too low number of iterations could cause an infinite loop because of being looking for a divisor of a prime number.